import { CloudDBZoneWrapper } from '../clouddb/CloudDBZoneWrapper.js';
import * as Utils from '../utils/Utils.js';

const TAG: string = 'cloudDB-->';
/**
 event: {"id_list": [1,2]}
 */
export const myHandler = async function (event, context, callback, logger) {
  const credential = Utils.getCredential(context, logger);
  try {
    const cloudDBZoneWrapper = new CloudDBZoneWrapper(credential, logger);
    let bornList = cloudDBZoneWrapper.getBornForDelete(event.id_list);
    let result = await cloudDBZoneWrapper.deleteRecord(bornList);
    if (result) {
      callback({
        result: { code: 0, desc: "SUCCESS" },
      });
    }else{
      callback({
        result: { code: -1, desc: "FAILED" },
      });
    }
  } catch (err) {
    logger.error(TAG + "func error:" + err.message + " stack:" + err.stack);
    callback({
      result: { code: -1, desc: "ERROR" },
    });
  }
};